﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}
<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>



<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>客户修改</title>
    <link href="//unpkg.com/layui@2.9.18/dist/css/layui.css" rel="stylesheet">
</head>
<body>
    <form class="layui-form" action="">
        <div class="layui-form" lay-filter="filter-test-layer" style="margin: 16px;">
            <div class="demo-login-container">
                <div class="layui-form-item">
                    <div class="layui-input-group">
                        <div class="layui-input-prefix" style="left:28px">
                            入库单编码
                        </div>

                        <div style="width:400px;left:28px">
                            <input style="width:400px" type="text" name="PurchaseNo" value="" lay-verify="required" placeholder="请输入入库单编码" lay-reqtext="请填写入库单编码" autocomplete="off" class="layui-input" lay-affix="clear">
                        </div>
                        <div style="left:27px">
                            <button type="button" class="layui-btn layui-btn-primary layui-btn-xs" onclick="nodeAlls()">自动生成</button>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-group">
                        <div class="layui-input-prefix" style="left:28px">
                            入库单名称
                        </div>
                        <div style="width:500px;left:28px">
                            <input style="width:500px" type="text" name="PurchaseName" value="" lay-verify="required" placeholder="请输入入库单名称" lay-reqtext="请填写 入库单名称" autocomplete="off" class="layui-input" lay-affix="clear">
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-group">
                        <div class="layui-input-prefix" style="left:28px">
                            入库时间
                        </div>
                        <div style="width:220px;left:28px">
                            <input style="width:210px" type="date" name="PurchaseDate" value="" lay-verify="required" placeholder="请输入出库日期" lay-reqtext="请填写出库日期" autocomplete="off" class="layui-input" lay-affix="clear">
                        </div>

                    </div>
                </div>


                <div class="layui-form-item">
                    <div class="layui-input-group">
                        <div class="layui-input-prefix" style="left:28px">
                            到货通知单
                        </div>
                        <div style="width:150px;left:28px">
                            <input style="width:150px" type="text" name="ArrivalNoticeId" value="" lay-verify="required" placeholder="请输入到货通知单" lay-reqtext="请填写到货通知单" autocomplete="off" class="layui-input" lay-affix="clear">
                        </div>
                        <div style="left:19px">
                            <button type="button" class="layui-btn layui-btn-primary" lay-on="test-page-customes">
                                <i class="layui-icon layui-icon-search"></i>
                            </button>
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-group">
                        <div class="layui-input-prefix" style="left:28px">
                            采购订单号
                        </div>
                        <div style="width:500px;left:28px">
                            <input style="width:500px" type="text" name="PurchaseIndentId" value="" lay-verify="required" placeholder="请输入采购订单号" lay-reqtext="请填写采购订单号" autocomplete="off" class="layui-input" lay-affix="clear">
                        </div>
                    </div>
                </div>

                <div class="layui-input-group">
                    <div class="layui-input-prefix" style="left:28px">
                        供应商
                    </div>
                    <div style="width:150px;left:28px">
                        <input style="width:150px" type="text" name="supplierName" value="" lay-verify="required" placeholder="请输入供应商" lay-reqtext="请填写供应商" autocomplete="off" class="layui-input" lay-affix="clear">
                    </div>
                    <div style="left:19px">
                        <button type="button" class="layui-btn layui-btn-primary" lay-on="test-page-customs">
                            <i class="layui-icon layui-icon-search"></i>
                        </button>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-group">
                    <div class="layui-input-prefix" style="left:28px">
                        备注
                    </div>
                    <div style="width:300px;left:28px">
                        <textarea style="width:400px" type="textarea" name="Remark" value="" lay-verify="required" placeholder="请输入备注" lay-reqtext="请填写备注" autocomplete="off" class="layui-input layui-textarea" lay-affix="clear"></textarea>
                    </div>
                </div>
            </div>

          
        </div>

        <div>      -------------------------------------------------------------------------------------------------------------物料信息-------------------------------------------------------------------------------------------------------------</div>
        <div class="layui-panel">
            <div style="padding: 32px;">
                <form class="layui-form" action="">
                   
                    <div class="layui-form-item">
                        <div class="layui-input-group">
                            <div>
                                <button type="button" class="layui-btn layui-btn-sm layui-btn-primary layui-border-blue" lay-on="test-page-custtom">
                                    <i  class="layui-icon layui-icon-add-1">新增</i>
                                </button>
                            </div>
                        </div>

                        <table style="left:320px" class="layui-table">
                            <thead>
                                <tr>
                                    <td><input type="checkbox" id="quanxuan" onclick="xuanzhe()" value="" /></td>
                                    <td>物料编号</td>
                                    <td>物料名称</td>
                                    <td>规格型号</td>
                                    <td>单位</td>
                                    <td>入库数量</td>
                                    <td>批次号</td>
                                    <td>仓库</td>
                                    <td>操作</td>
                                </tr>
                            </thead>
                            <tbody></tbody>
                        </table>
                        <div id="demo-laypage-all"></div>
                    </div>
                </form>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-group">
                <div class="layui-form-item" style="left:200px">
                    <button class="layui-btn layui-btn-normal" onclick=" UpdateClient()">修改</button>
                    <button class="layui-btn layui-btn-primary" lay-filter="demo-Break">取消</button>
                    <input type="hidden" name="SupplierId" value="">
                </div>
            </div>
        </div>
    </form>
     <script>
         layui.use(['form', 'laydate', 'util', 'table'], function () {
             var form = layui.form;
             var laypage = layui.laypage;
             var layer = layui.layer;
             var $ = layui.$;
             var laydate = layui.laydate;
             var util = layui.util;
            util.on('lay-on', {
                'test-page-custtom': function () {
                    layer.open({
                        type: 2,
                        area: ['1200px', '600px'],
                        maxmin: true,
                        shadeClose: true,
                        title: '物料信息',
                        content: `/Enterprise/MaterialAdd`,
                    });
                }
            });
         });
        
    </script> 
<script>
    var $ = layui.$;
    var layer = layui.layer;
    var util = layui.util;
    var form = layui.form;
    layui.use(function () {
        // 事件
        util.on('lay-on', {
            'test-page-customs': function () {
                layer.open({
                    type: 1,
                    area: '100%',
                    resize: false,
                    shadeClose: true,
                    title: '供应商',
                    content: `
                                    <form class="layui-form" action="">
                    <div class="layui-form">
                        <div class="layui-form-item">
                            <div class="layui-input-group">
                                <div class="layui-input-prefix">
                                    供应商编码
                                </div>
                                <div>
                                    <input id="supplierNo" type="text" placeholder="请输入供应商编码" class="layui-input">
                                </div>

                                <div class="layui-input-prefix" style="left:50px">
                                    供应商名称
                                </div>
                                <div style="left:50px">
                                    <input id="supplierName" type="text" placeholder="请输入供应商名称" class="layui-input">
                                </div>

                                <div class="layui-input-prefix" style="left:100px">
                                    供应商简称
                                </div>
                                <div style="left:100px">
                                    <input id="supplierShort" type="text" placeholder="请输入供应商简称" class="layui-input">
                                </div>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <div class="layui-input-group">
                                <div class="layui-input-prefix" style="left:14px">
                                    英文名称
                                </div>
                                <dic style="left:14px">
                                    <input id="supplierEnglishName" type="text" placeholder="请输入供应商英文名称" class="layui-input">
                                </dic>

                                <div class="layui-input-prefix" style="left:77px">
                                    是否启用
                                </div>
                                <div style="left:77px;width:197px">
                                    <select id="supplierIsNo" lay-filter="testSelect">
                                        <option value="-1">是否启用</option>
                                        <option value="0">禁用</option>
                                        <option value="1">启用</option>
                                    </select>
                                </div>

                                <div style="left:150px">
                                    <button onclick="ShowSupplier()" id="searchBtn" type="button" class="layui-btn layui-btn-normal">搜索</button>

                                </div>

                                <div style="left:170px">
                                    <button onclick="Break()" type="button" class="layui-btn layui-btn-primary">重置</button>
                                </div>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <div class="layui-input-group">
                                <div>
                                    <button type="button" class="layui-btn layui-btn-sm layui-btn-primary layui-border-blue" lay-on="test-page-custom">
                                        <i class="layui-icon layui-icon-add-1">新增</i>
                                    </button>
                                </div>
                            </div>
                        </div>

                        <table style="left:320px" class="layui-table">
                            <thead>
                                <tr>
                                    <td>供应商编码</td>
                                    <td>供应商名称</td>
                                    <td>供应商简称</td>
                                    <td>供应商等级</td>
                                    <td>供应商评分</td>
                                    <td>供应商电话</td>
                                    <td>是否启用</td>
                                    <td>备注</td>
                                    <td>操作</td>
                                </tr>
                            </thead>
                                    <tbody id="ClientTable"></tbody>
                        </table>
                        <div id="demo-laypage-all"></div>
                    </div>
                </form>
                `,
                    success: function () {
                        var form = layui.form;
                        var laypage = layui.laypage;
                        var layer = layui.layer;
                        var $ = layui.$;
                        var laydate = layui.laydate;
                        var util = layui.util;

                        var pageIndex = 1;
                        var pageSize = 2;

                        $(function () {
                            ShowSupplier(pageIndex, pageSize);
                        })
                        // 获取供应商编码
                        $('#searchBtn').click(function () {
                            var supplier = $('#supplierNo').val();
                            ShowSupplier(pageIndex, pageSize)
                        });
                        // 获取供应商名称
                        $('#searchBtn').click(function () {
                            var supplier1 = $('#supplierName').val();
                            ShowSupplier(pageIndex, pageSize)
                        });
                        //供应商简称
                        $('#searchBtn').click(function () {
                            var supplier2 = $('#supplierShort').val();
                            ShowSupplier(pageIndex, pageSize)
                        });
                        // 英文名称
                        $('#searchBtn').click(function () {
                            var supplier2 = $('#supplierEnglishName').val();
                            ShowSupplier(pageIndex, pageSize)
                        });
                        //是否启用
                        form.on('select(testSelect)', function (data) {
                            ShowPermission(data.value); // data.value
                        });
                        //供应商管理列表
                        function ShowSupplier(index, size) {
                            var supplierNo = $("#supplierNo").val() || "";
                            var supplierName = $("#supplierName").val() || "";
                            var supplierShort = $("#supplierShort").val() || "";
                            var supplierEnglishName = $("#supplierEnglishName").val() || "";
                            var supplierIsNo = $("#supplierIsNo").val() || -1;
                            $.ajax({
                                url: '@ViewBag.FoundationRead' + "/api/UserLi/SearchSupplier",
                                data: JSON.stringify({ supplierNo: supplierNo, supplierName: supplierName, supplierShort: supplierShort, supplierEnglishName: supplierEnglishName, supplierIsNo: supplierIsNo, pageIndex: index, pageSize: size }),
                                type: "post",
                                async: false,
                                dataType: "json",
                                contentType: "application/json",
                                success: res => {
                                    var tbody = $("tbody");
                                    tbody.empty();
                                    if (res.data != null) {
                                        $.each(res.data, function () {
                                            tbody.append(`<tr>
                                            <td>${this.supplierNo}</td>
                                            <td>${this.supplierName}</td>
                                            <td>${this.supplierShort}</td>
                                            <td>${this.supplierClassName}</td>
                                            <td>${this.supplieScore}</td>
                                            <td>${this.supplierPhone}</td>
                                            <td>${this.supplierIsNo === 1 ? '启用' : '禁用'}</td>
                                            <td>${this.supplierRemark}</td>
                                            <td><a onclick="GetClient(${this.supplierId},'${this.supplierNo}','${this.supplierName}')" class="btn btn-link">选择</a></td>
                                        </tr>`);
                                        });
                                    }
                                    form.render(); // 重新渲染下拉框
                                    //完整显示
                                    laypage.render({
                                        elem: 'demo-laypage-all', // 元素 id
                                        count: res.totalCount, // 数据总数
                                        curr: index,//当前页
                                        limit: size,//每页几条
                                        limits: [2, 3, 4],
                                        layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip'], // 功能布局
                                        jump: function (obj, first) {
                                            if (!first) {
                                                ShowSupplier(obj.curr, obj.limit);
                                            }
                                        }
                                    });
                                }
                            })
                        }
                        // 对弹层中的表单进行初始化渲染
                        form.render();
                        // 表单提交事件
                        form.on('submit(demo-Search)', function (data) {
                            var field = data.field; // 获取表单字段值

                            // 显示填写结果，仅作演示用
                            // layer.alert(JSON.stringify(field), {
                            //     title: '当前填写的字段值'
                            // });
                            // 此处可执行 Ajax 等操作
                            // …

                            return false; // 阻止默认 form 跳转
                        });
                    }
                });
            }
        })
    });
    function GetClient(supplierId, supplierNo, supplierName) {
        localStorage.setItem("supplierId", supplierId);
        $("[name='supplierNos']").val(supplierNo);
        $("[name='supplierName']").val(supplierName);
        layer.close(layer.index); // 关闭弹层
        form.render(); // 重新渲染
    }
</script>
  
<script>
    var form = layui.form;
    var $ = layui.$;
    var layer = layui.layer;
    var util = layui.util;
    var laydate = layui.laydate;
    var laypage = layui.laypage;

    var pageIndex = 1;
    var pageSize = 2;
    //自动生成编码
    function nodeAlls() {
        var datec = new Date()
        var year = datec.getFullYear();
        var month = (datec.getMonth() + 1).toString().padStart(2, "0")
        var date = (datec.getDate() + 1).toString().padStart(2, "0")
        var hours = datec.getHours()
        var minute = (datec.getMinutes()).toString().padStart(2, "0")
        var seconds = (datec.getSeconds()).toString().padStart(2, "0")
        // var Encoding = "IF";
        var result = "IF" + year + month + date + hours + minute + seconds;
        console.log(result);
        $("[name='PurchaseNo']").val(result);

        //重新渲染表单
        form.render();
    }

  
    layui.use(['form', 'laydate', 'util', 'table'], function () {
        var form = layui.form;
        var laypage = layui.laypage;
        var layer = layui.layer;
        var $ = layui.$;
        var laydate = layui.laydate;
        var util = layui.util;

        var pageIndex = 1;
        var pageSize = 2;
        $(function () {
            GetClientType();
            
            
        });
        
        function GetClientType() {
        return new Promise(function (resolve, reject) {
            $(document).ready(function () {
                var purchaseId = localStorage.getItem("purchaseId");
                console.log(purchaseId);
                if (purchaseId) {
                    $.ajax({
                        type: "post",
                        url: '@ViewBag.FoundationWrite' + '/api/Jocker/PurchaseStorageBack',
                        data: JSON.stringify({ PurchaseId: purchaseId }),
                        asyn: false,
                        dataType: "json",
                        contentType: "application/json",
                        success: function (res) {
                            if (res.data) {
                                const cli = res.data;

                                $("[name='PurchaseNo']").val(cli[0].purchaseNo);
                                $("[name='PurchaseName']").val(cli[0].purchaseName);
                                $("[name='PurchaseDate']").val(cli[0].purchaseDate.substr(0,10));
                                $("[name='ArrivalNoticeId']").val(cli[0].arrivalNoticeId);
                                $("[name='PurchaseIndentId']").val(cli[0].purchaseIndentId);
                                $("[name='supplierName']").val(cli[0].supplierName);
                                $("[name='Remark']").val(cli[0].remark);
                                $("[name='SupplierId']").val(cli[0].supplierId);
                                MaterialList(pageIndex, pageSize);
                                resolve(cli);
                            } else {
                                layer.msg(res.message);
                            }
                            form.render();
                        }
                    });

                }

            });
        });
    }
        function MaterialList(index, size) {
            //var table = document.querySelector("table.layui-table tbody");
            console.log($("[name='PurchaseNo']").val());
            console.log(11111);
            $.ajax({
                url: '@ViewBag.FoundationWrite' + "/api/Jocker/MaterialList",
                data: JSON.stringify({purchaseNo: $("[name='PurchaseNo']").val(), pageIndex: index, pageSize: size }),
                type: "post",
                async: false,
                dataType: "json",
                contentType: "application/json",
                success: res => {
                    var tbody = $("tbody");
                    tbody.empty();
                    if (res.data != null) {
                        $.each(res.data, function () {
                            console.log(res.data)
                            tbody.append(`<tr>
                                      <td><input type="checkbox" class="checked" value="${this.materialId}" name="check"/></td>
                                      <td>${this.productManageNode}</td>
                                      <td>${this.productManageName}</td>
                                      <td>${this.productManageNumber}</td>
                                      <td>${this.unites}</td>
                                      <td>${this.num}</td>
                                      <td>${this.batch}</td>
                                      <td>${this.stashName}</td>
                                      <td>
                                      <a onclick="EditSupplier(${this.materialId})" class="btn btn-link layui-btn-xs" lay-on="test-page-customse"">修改</a>
                                     </td>
                                 </tr>`)

                        });
                        form.render(); // 重新渲染下拉框
                        laypage.render({
                            elem: 'demo-laypage-all', // 元素 id
                            count: res.totalCount, // 数据总数
                            curr: index,//当前页
                            limit: size,//每页几条
                            limits: [2, 3, 4],
                            layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip'], // 功能布局
                            jump: function (obj, first) {
                                if (!first) {
                                    MaterialList(obj.curr, obj.limit);
                                }
                            }
                        });
                    }
                }
            });
        }
    });


    


    function UpdateClient() {
        var purchaseId = localStorage.getItem("purchaseId");
        let aa = {
            PurchaseId: purchaseId,
            PurchaseNo: $("[name='PurchaseNo']").val(),
            PurchaseName: $("[name='PurchaseName']").val(),
            PurchaseDate: $("[name='PurchaseDate']").val(),
            ArrivalNoticeId: $("[name='ArrivalNoticeId']").val(),
            PurchaseIndentId: $("[name='PurchaseIndentId']").val(),
            supplierName: $("[name='supplierName']").val(),
            SupplierId: $("[name='SupplierId']").val(),
            Remark: $("[name='Remark']").val(),
            ReceiptState: "草稿",
        };
        console.log(aa);
        $.ajax({
            type: "post",
            url: '@ViewBag.FoundationWrite' + '/api/Jocker/PurchaseStorageUpdate',
            data: JSON.stringify(aa),
            asyn: false,
            dataType: "json",
            contentType: "application/json",
            success: res => {
                if (res.code > 0) {
                    alert('修改成功');
                    layer.close(layer.index); // 关闭弹层
                } else {
                    alert('修改失败');
                }
            }
        });
    }

</script>
    </body> 
</html>

